package com.matrix.calculator;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.text.TextPaint;
import android.util.DisplayMetrics;
import android.view.View;

public class ResultsDrawable extends View{
	private Context mContext;
	
	private String[][] strmtrx;
	private int[] maxColLength;
	private int height;
	private int width;
	private int textHeight;
	 
	public ResultsDrawable(Context context, String[][] s, int[] max) 
	{
		super(context);
		mContext = context;
		strmtrx = s;
		maxColLength = max;
		TextPaint pt = new TextPaint();
		Rect r = new Rect();
		int scaledSize = getResources().getDimensionPixelSize(R.dimen.font_size);
		pt.setTextSize(scaledSize);
		pt.getTextBounds("g", 0, 1, r);
		textHeight = r.height();
		height = (strmtrx.length)*(r.height()+15)+20;
    	width = 10;
    	for(int i=0; i<maxColLength.length; i++)
    	{
    		if(i<maxColLength.length-1)
    		{
    			width +=  maxColLength[i] +15;
    		}
    		else
    		{
    			width +=  maxColLength[i];
    		}
    	}
		//sets the levels 
	}
	
	/**
	 * draws the map to the canvas
	 */
	protected void onDraw(Canvas canvas)
	{
		
		Paint p = new Paint();
		p.setARGB(255, 0, 0, 0);
		int scaledSize = getResources().getDimensionPixelSize(R.dimen.font_size);
		p.setTextSize(scaledSize);
		Paint brackets = new Paint();
		brackets.setARGB(255, 0,0 , 0);
		brackets.setStrokeWidth(brackets.getStrokeWidth()+2);
		canvas.drawLine(3, height-17, 3, 1, brackets);
		canvas.drawLine(3,1, 13, 1, brackets);
		canvas.drawLine(3, height-17, 13, height-17, brackets);
		int starty = (int) ((textHeight)/2.5);
		
		for(int i=0; i<strmtrx[0].length; i++)
		{
			for(int j=0; j<strmtrx.length; j++)
			{
				if(i==0)
				{
					canvas.drawText(strmtrx[j][i], 10, textHeight+starty + (textHeight+15)*j, p);
				}
				else
				{
					int w = 10;
					for(int l=i-1; l>=0; l--)
			    	{
			    		w +=  maxColLength[l]+15;
			    	}
					canvas.drawText(strmtrx[j][i], w, textHeight+starty + (textHeight+15)*j, p);
				}
				
			}
		}
		canvas.drawLine(width+5, height-17, width+5, 1, brackets);
		canvas.drawLine(width+5, 1, width-5, 1, brackets);
		canvas.drawLine(width+5, height-17, width-5, height-17,brackets);
		invalidate();
	}
	public int height()
	{
		return height;
	}
	public int width()
	{
		return width;
	}
	
}

